﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Gizmox.WebGUI.Forms;

namespace TVC.Modules.CustomControl
{
    public class MyHtmlbox : Gizmox.WebGUI.Forms.HtmlBox
    {
        //String sErr = "";
        //String defaultvalue = "";
        //frmInputData frminput = new frmInputData();
        String[] valuep1 = new string[100];
        public delegate void FireEventHandle(string command, string args);
        public event FireEventHandle OnFireEvent;

        public static string Base64ToString(string b64)
        {
            byte[] b = Convert.FromBase64String(b64);
            return (System.Text.Encoding.UTF8.GetString(b));
        }
        protected override void FireEvent(Gizmox.WebGUI.Common.Interfaces.IEvent objEvent)
        {
            base.FireEvent(objEvent);

            if (objEvent.Type == "TaViCo_Link")
            {
                String args = objEvent["LinkInfo"];
                String[] s = args.Split(new string[] { "//" }, StringSplitOptions.None);
                if (s.Length > 0)
                {
                    String[] cmd = s[1].Split('?');
                    if (cmd.Length >= 1)
                    {
                        if (OnFireEvent != null)
                        {
                            if (s[1].Length > cmd[0].Length)
                                OnFireEvent(cmd[0].Replace("/",""), s[1].Substring(cmd[0].Length + 1));
                            else OnFireEvent(cmd[0].Replace("/", ""), "");
                        }
                    }
                }

            }
        }

        //void frminput_FormClosed(object sender, Gizmox.WebGUI.Forms.FormClosedEventArgs e)
        //{
        //    if (((frmInputData)sender).DialogResult == DialogResult.OK)
        //    {
        //        defaultvalue = ((frmInputData)sender).Type + "=" + ((frmInputData)sender).valuereturn;

        //        FrmMain frm = (FrmMain)this.Parent.Parent;
        //        BUS.LIST_GADGETControl ctr = new BUS.LIST_GADGETControl();

        //        MyGadget mygadget = new MyGadget(frm._gui, frm.inf, defaultvalue);

        //        String file = mygadget.Init();
        //        frm.Xls = mygadget.Xls;
        //        if (file != "")
        //            frm.LoadGadget(file);
        //    }
        //}
    }
}
